<!DOCTYPE html>
<html lang="en" >
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="ThemeBucket">
    <link rel="shortcut icon" href="#" type="image/png">

    <title>去注册</title>

    <link href="css/style.css" rel="stylesheet">
    <link href="css/external/style-responsive.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--    &lt;!&ndash;[if lt IE 9]>-->
<!--    <script src="js/html5shiv.js"></script>-->
<!--    <script src="js/respond.min.js"></script>-->
    <![endif]-->
</head>

<body class="login-body">

<div class="container">
<!--    onsubmit="return test1()"-->
    <form id="siginFrom" class="form-signin"  >
        <div class="form-signin-heading text-center">
            <h1 class="sign-title">新用户注册</h1>
            <img src="images/login-logo.png" alt=""/>
        </div>

        <div class="login-wrap">
            <p>输入您的帐户详细信息如下</p>
            <input type="text" autofocus="" name="username" placeholder="用户名" class="form-control">
            <input type="password" id="password1" name="password" placeholder="密码" class="form-control">
            <input type="text" autofocus="" id="email1" name="email" placeholder="邮箱" class="form-control">
            <div>
                <input type="text" name="vercode" placeholder="邮箱验证码" class="form-control">
                <button type="button" id="ver-btn">获取验证码</button>
            </div>
            <button  type="button" id="btn-submit" class="btn btn-lg btn-login btn-block" >
                <i class="fa fa-check"></i>
            </button>

            <div class="registration">
                已经注册。
                <a href="js/login.html" class="">
                    去登陆
                </a>
            </div>

        </div>

    </form>

</div>



<!-- Placed js at the end of the document so the pages load faster -->

<!-- Placed js at the end of the document so the pages load faster -->
<!--<script src="js/md5.js"></script>-->
<script src="js/external/jquery-3.4.1.min.js"></script>
<script src="js/external/jquery.md5.js" type="text/javascript" charset="utf-8"></script>
<script src="js/external/bootstrap.min.js"></script>
<script src="js/external/modernizr.min.js"></script>
<script>


    $(function () {
        $("#btn-submit").click(function () {
            var username = $('[name="username"]').val()
            var password = $.md5($('[name="password"]').val())
            var email = $('[name="email"]').val()
            var vercode = $('[name="vercode"]').val()
            var data ={
                'userName':username,
                    'password':password,
                    'email':email,
                    'vercode' :vercode
            }
            $.ajax({
                url:"user/register",
                method:"post",
                data:data,
                beforeSend: function () {
                    console.log(123456)
                },
                success:function (data) {
                    if (data.code==200){
                        alert(data.message)
                        window.location.href="login.html"
                    }else {
                        alert(data.message)
                    }
                },
                error:function (data) {
                    alert("服务器异常，请联系管理员")
                }
            })
        })


         //邮箱按键60秒倒计时
         var wait = 60;
        function time(o){
            var x
            if (wait == 0){
                o.removeAttribute("disabled");
                o.innerHTML="重新获取邮箱验证"
                wait = 60
            }else{
                o.setAttribute("disabled",true)
                o.innerHTML="重新发送("+wait-- +")秒"
                // console.log("重新发送("+wait +")秒")
                //wait--;
                x = setTimeout(function () {
                    time(o)
                },1000)
            }
        }


        /**
         * 获取邮箱验证码
         */
        $("#ver-btn").click(function () {
            time(this)
            var email = $("#email1").val();
            console.log(email)
            $.ajax({
                url:"getVercode/"+email,
                method:"get",
                beforeSend:function () {
                    console.log(123456)
                },
                success:function (data) {
                    if (data.code==200){
                        alert(data.message)
                    }else if (data.code==400){
                        alert(data.message)
                    }
                },
                error:function (data) {
                    alert("系统故障，请联系管理员！")
                }
            })
        })

    })


</script>

</body>
</html>
